Beatriz Castelo
Matilde Reis
3º ano Licenciatura em Engenharia e Ciência de Dados
Unidade Curricular - Visualização de Dados
import numpy as np
import os
import pandas as pd
paths = "/Users/Asus/women's _rights"
dat = sorted(os.listdir(paths))
data = []
for path in dat:
todos_path = os.path.join(paths, path)
df = pd.read_csv(todos_path)
data.append(df)
# remover a coluna Code que não interfere no problema
for i in range(len(data)):
data[i] = data[i].drop('Code', axis=1)
# verificar existência de valores em falta
for df in data:
valor_falta = df.isnull().sum()
print(valor_falta)
print('--------')
Entity 0 Year 0 Female to male ratio of time devoted to unpaid care work (OECD (2014)) 0 dtype: int64 -------- Entity 0 Year 0 Share of women in top 0.1% 37 Share of women in top 0.25% 131 Share of women in top 0.5% 86 Share of women in top 1% 1 Share of women in top 10% 0 Share of women in top 5% 0 dtype: int64 -------- Entity 0 Year 0 Ratio of female to male labor force participation rate (%) (modeled ILO estimate) 0 dtype: int64 -------- Entity 0 Year 0 Female to male ratio of time devoted to unpaid care work (OECD (2014)) 0 dtype: int64 -------- Entity 0 Year 0 Maternal Mortality Ratio (Gapminder (2010) and World Bank (2015)) 0 dtype: int64 -------- Entity 0 Year 0 Gender wage gap (%) 0 dtype: int64 --------
df_ratio = data[0] #Female to male ratio of time devoted to unpaid care work (OECD (2014)
df_share = data[1] # Share of women in top 0.1% Share of women in top 0.25% Share of women in top 0.5% Share of women in top 1% Share of women in top 10% Share of women in top 5%
df_ratio_female_male = data[2] # Ratio of female to male labor force participation rate (%) (modeled ILO estimate)
del data[3] # é igual ao data[0]
df_mortality = data[3] # Maternal Mortality Ratio (Gapminder (2010) and World Bank (2015))
df_gender = data[4] # Gender wage gap (%)
# substituir os valores em falta pela média
'''
Share of women in top 0.1% 37
Share of women in top 0.25% 131
Share of women in top 0.5% 86
Share of women in top 1% 1
'''
df_share['Share of women in top 0.1%'] = df_share['Share of women in top 0.1%'].fillna(df_share['Share of women in top 0.1%'].mean())
df_share['Share of women in top 0.25%'] = df_share['Share of women in top 0.25%'].fillna(df_share['Share of women in top 0.25%'].mean())
df_share['Share of women in top 0.5%'] = df_share['Share of women in top 0.5%'].fillna(df_share['Share of women in top 0.5%'].mean())
df_share['Share of women in top 1%'] = df_share['Share of women in top 1%'].fillna(df_share['Share of women in top 1%'].mean())
# verificar se os valores em falta foram tratados
for df in data:
valor_falta = df.isnull().sum()
print(valor_falta)
print('--------')
Entity 0 Year 0 Female to male ratio of time devoted to unpaid care work (OECD (2014)) 0 dtype: int64 -------- Entity 0 Year 0 Share of women in top 0.1% 0 Share of women in top 0.25% 0 Share of women in top 0.5% 0 Share of women in top 1% 0 Share of women in top 10% 0 Share of women in top 5% 0 dtype: int64 -------- Entity 0 Year 0 Ratio of female to male labor force participation rate (%) (modeled ILO estimate) 0 dtype: int64 -------- Entity 0 Year 0 Maternal Mortality Ratio (Gapminder (2010) and World Bank (2015)) 0 dtype: int64 -------- Entity 0 Year 0 Gender wage gap (%) 0 dtype: int64 --------
# verificar nº de linhas duplicadas
for df in data:
print(f"Número de linhas duplicadas = {df.duplicated(keep='first').sum()}")
print('--------')
Número de linhas duplicadas = 0 -------- Número de linhas duplicadas = 0 -------- Número de linhas duplicadas = 0 -------- Número de linhas duplicadas = 0 -------- Número de linhas duplicadas = 0 --------
Filtragem dos Dados
drop = df_ratio_female_male[(df_ratio_female_male['Year'] > 2015)].index
df_ratio_female_male = df_ratio_female_male.drop(drop)
print(df_ratio_female_male)
Entity Year \
0 Afghanistan 1990
1 Afghanistan 1991
2 Afghanistan 1992
3 Afghanistan 1993
4 Afghanistan 1994
... ... ...
6421 Zimbabwe 2011
6422 Zimbabwe 2012
6423 Zimbabwe 2013
6424 Zimbabwe 2014
6425 Zimbabwe 2015
Ratio of female to male labor force participation rate (%) (modeled ILO estimate)
0 19.604805
1 19.713380
2 19.803307
3 19.844606
4 19.884710
... ...
6421 87.944496
6422 88.557370
6423 89.147710
6424 89.714264
6425 89.627426
[5226 rows x 3 columns]
drop = df_gender[(df_gender['Year'] < 1990) | (df_gender['Year'] > 2015)].index
df_gender = df_gender.drop(drop)
print(df_gender)
Entity Year Gender wage gap (%) 3 Argentina 1991 6.71 4 Argentina 1992 8.33 5 Argentina 1993 7.69 6 Argentina 1994 -2.27 7 Argentina 1995 4.44 .. ... ... ... 407 Venezuela 2003 0.30 408 Venezuela 2004 0.77 409 Venezuela 2005 5.10 410 Venezuela 2006 6.43 411 Vietnam 2015 7.69 [386 rows x 3 columns]
drop = df_mortality[(df_mortality['Year'] < 1990) | (df_mortality['Year'] > 2015)].index
df_mortality = df_mortality.drop(drop)
print(df_mortality)
Entity Year \
0 Afghanistan 2000
1 Afghanistan 2001
2 Afghanistan 2002
3 Afghanistan 2003
4 Afghanistan 2004
... ... ...
5793 Zimbabwe 2011
5794 Zimbabwe 2012
5795 Zimbabwe 2013
5796 Zimbabwe 2014
5797 Zimbabwe 2015
Maternal Mortality Ratio (Gapminder (2010) and World Bank (2015))
0 1450.0
1 1390.0
2 1300.0
3 1240.0
4 1180.0
... ...
5793 557.0
5794 528.0
5795 509.0
5796 494.0
5797 480.0
[3535 rows x 3 columns]
drop = df_share[(df_share['Year'] < 1990)].index
df_share = df_share.drop(drop)
print(df_share)
Entity Year Share of women in top 0.1% Share of women in top 0.25% \
0 Australia 2000 14.2 12.835135
1 Australia 2001 13.2 12.835135
2 Australia 2002 13.5 12.835135
3 Australia 2003 14.4 12.835135
4 Australia 2004 15.2 12.835135
.. ... ... ... ...
163 UK 2011 9.9 12.200000
164 UK 2012 11.9 13.500000
165 UK 2013 10.8 13.300000
166 UK 2014 11.4 13.900000
167 UK 2015 12.7 15.300000
Share of women in top 0.5% Share of women in top 1% \
0 14.731707 18.3
1 14.731707 18.4
2 14.731707 18.8
3 14.731707 19.1
4 14.731707 19.6
.. ... ...
163 14.400000 17.1
164 15.400000 17.7
165 15.600000 18.0
166 16.300000 18.6
167 17.100000 18.9
Share of women in top 10% Share of women in top 5%
0 24.9 21.1
1 25.1 21.4
2 25.1 21.5
3 25.1 21.6
4 25.5 22.2
.. ... ...
163 28.1 24.2
164 28.0 24.2
165 28.0 24.6
166 27.7 24.8
167 28.3 25.1
[148 rows x 8 columns]
pip install pycountry_convert
Requirement already satisfied: pycountry_convert in c:\users\asus\anaconda3\lib\site-packages (0.7.2) Requirement already satisfied: pytest>=3.4.0 in c:\users\asus\anaconda3\lib\site-packages (from pycountry_convert) (6.2.4) Requirement already satisfied: pycountry>=16.11.27.1 in c:\users\asus\anaconda3\lib\site-packages (from pycountry_convert) (22.3.5) Requirement already satisfied: pprintpp>=0.3.0 in c:\users\asus\anaconda3\lib\site-packages (from pycountry_convert) (0.4.0) Requirement already satisfied: pytest-mock>=1.6.3 in c:\users\asus\anaconda3\lib\site-packages (from pycountry_convert) (3.12.0) Requirement already satisfied: repoze.lru>=0.7 in c:\users\asus\anaconda3\lib\site-packages (from pycountry_convert) (0.7) Requirement already satisfied: pytest-cov>=2.5.1 in c:\users\asus\anaconda3\lib\site-packages (from pycountry_convert) (4.1.0) Requirement already satisfied: wheel>=0.30.0 in c:\users\asus\anaconda3\lib\site-packages (from pycountry_convert) (0.37.0) Requirement already satisfied: setuptools in c:\users\asus\anaconda3\lib\site-packages (from pycountry>=16.11.27.1->pycountry_convert) (58.0.4) Requirement already satisfied: attrs>=19.2.0 in c:\users\asus\anaconda3\lib\site-packages (from pytest>=3.4.0->pycountry_convert) (21.2.0) Requirement already satisfied: iniconfig in c:\users\asus\anaconda3\lib\site-packages (from pytest>=3.4.0->pycountry_convert) (1.1.1) Requirement already satisfied: packaging in c:\users\asus\anaconda3\lib\site-packages (from pytest>=3.4.0->pycountry_convert) (21.0) Requirement already satisfied: pluggy<1.0.0a1,>=0.12 in c:\users\asus\anaconda3\lib\site-packages (from pytest>=3.4.0->pycountry_convert) (0.13.1) Requirement already satisfied: py>=1.8.2 in c:\users\asus\anaconda3\lib\site-packages (from pytest>=3.4.0->pycountry_convert) (1.10.0) Requirement already satisfied: toml in c:\users\asus\anaconda3\lib\site-packages (from pytest>=3.4.0->pycountry_convert) (0.10.2) Requirement already satisfied: atomicwrites>=1.0 in c:\users\asus\anaconda3\lib\site-packages (from pytest>=3.4.0->pycountry_convert) (1.4.0) Requirement already satisfied: colorama in c:\users\asus\anaconda3\lib\site-packages (from pytest>=3.4.0->pycountry_convert) (0.4.6) Requirement already satisfied: coverage[toml]>=5.2.1 in c:\users\asus\anaconda3\lib\site-packages (from pytest-cov>=2.5.1->pycountry_convert) (7.3.2) Requirement already satisfied: tomli in c:\users\asus\anaconda3\lib\site-packages (from coverage[toml]>=5.2.1->pytest-cov>=2.5.1->pycountry_convert) (2.0.1) Requirement already satisfied: pyparsing>=2.0.2 in c:\users\asus\anaconda3\lib\site-packages (from packaging->pytest>=3.4.0->pycountry_convert) (3.0.4) Note: you may need to restart the kernel to use updated packages.
# juntar cada país por continentes
import pandas as pd
import pycountry_convert as pc
def country_to_continent(country_name):
try:
country_code = pc.country_name_to_country_alpha2(country_name, cn_name_format="default")
continent_code = pc.country_alpha2_to_continent_code(country_code)
continent_name = pc.convert_continent_code_to_continent_name(continent_code)
return continent_name
except:
return None
df_ratio['Continent'] = df_ratio['Entity'].apply(country_to_continent)
df_share['Continent'] = df_share['Entity'].apply(country_to_continent)
df_ratio_female_male['Continent'] = df_ratio_female_male['Entity'].apply(country_to_continent)
df_mortality['Continent'] = df_mortality['Entity'].apply(country_to_continent)
df_gender['Continent'] = df_gender['Entity'].apply(country_to_continent)
# calcular a média para cada país
df_ratio_avg = df_ratio.groupby(['Continent', 'Year']).mean(numeric_only=True).reset_index()
df_share_avg = df_share.groupby(['Continent', 'Year']).mean(numeric_only=True).reset_index()
df_ratio_female_male_avg = df_ratio_female_male.groupby(['Continent', 'Year']).mean(numeric_only=True).reset_index()
df_mortality_avg = df_mortality.groupby(['Continent', 'Year']).mean(numeric_only=True).reset_index()
df_gender_avg = df_gender.groupby(['Continent', 'Year']).mean(numeric_only=True).reset_index()
# visualização 1
from dash import Dash, dcc, html, Input, Output
import plotly.express as px
import pandas as pd
import plotly.graph_objects as go
df_ratio_avg['Indicator'] = 'Female to male ratio of time devoted to unpaid care work'
df_share_avg['Indicator'] = 'Share of Women in Top Percentiles'
df_ratio_female_male_avg['Indicator'] = 'Ratio of Female to Male Labor Force Participation Rate'
df_mortality_avg['Indicator'] = 'Maternal Mortality Ratio'
df_gender_avg['Indicator'] = 'Gender Wage Gap'
dataframes = {
'Female to male ratio of time devoted to unpaid care work' : ('df_ratio_avg', 'Female to male ratio of time devoted to unpaid care work (OECD (2014))'),
'Share of Women in Top Percentiles': ('df_share_avg', 'Share of women in top 0.1%'),
'Ratio of Female to Male Labor Force Participation Rate': ('df_ratio_female_male_avg', 'Ratio of female to male labor force participation rate (%) (modeled ILO estimate)'),
'Maternal Mortality Ratio': ('df_mortality_avg', 'Maternal Mortality Ratio (Gapminder (2010) and World Bank (2015))'),
'Gender Wage Gap': ('df_gender_avg', 'Gender wage gap (%)')
}
thisdict = {
0: 'Female to male ratio of time devoted to unpaid care work',
1: 'Share of Women in Top Percentiles',
2: 'Ratio of Female to Male Labor Force Participation Rate',
3: 'Maternal Mortality Ratio',
4: 'Gender Wage Gap'
}
list_df = [df_ratio_avg, df_share_avg, df_ratio_female_male_avg,df_mortality_avg, df_gender_avg]
df_ratio_avg.rename(columns={'Female to male ratio of time devoted to unpaid care work (OECD (2014))': 'Value'}, inplace=True)
df_share_avg.rename(columns={'Share of women in top 0.1%': 'Value'}, inplace=True) # Choose the appropriate column if you have multiple
df_ratio_female_male_avg.rename(columns={'Ratio of female to male labor force participation rate (%) (modeled ILO estimate)': 'Value'}, inplace=True)
df_mortality_avg.rename(columns={'Maternal Mortality Ratio (Gapminder (2010) and World Bank (2015))': 'Value'}, inplace=True)
df_gender_avg.rename(columns={'Gender wage gap (%)': 'Value'}, inplace=True)
combined_df = pd.concat([df_ratio_avg, df_share_avg, df_ratio_female_male_avg, df_mortality_avg, df_gender_avg])
app = Dash(__name__)
app.layout = html.Div([
html.H4('Time Series by Continent for All Indicators'),
dcc.Dropdown(
id="continent-selector",
options=[{'label': continent, 'value': continent} for continent in combined_df['Continent'].unique()],
value=combined_df['Continent'].unique()[2],
clearable=False,
),
dcc.Graph(id="combined-indicators-chart"),
])
@app.callback(
Output("combined-indicators-chart", "figure"),
Input("continent-selector", "value"))
def display_combined_chart(selected_continent):
traces = []
layout = go.Layout(
title='Gender-Related Indicators by Continent',
xaxis_title='Year',
yaxis_title='Indicator Value'
)
for key, (df_name, _) in dataframes.items():
df = globals()[df_name]
df_filtered = df[df['Continent'] == selected_continent]
traces.append(go.Scatter(
x=df_filtered['Year'],
y=df_filtered['Value'],
name=key
))
fig = go.Figure(data=traces, layout=layout)
return fig
app.run_server(debug=True, port=8080, mode='inline')
from dash import html
from dash.dependencies import Input, Output
from plotly.subplots import make_subplots
df_ratio_female_male_avg['Indicator'] = 'Ratio of Female to Male Labor Force Participation Rate'
df_gender_avg['Indicator'] = 'Gender Wage Gap'
df_mortality_avg['Indicator'] = 'Maternal Mortality Ratio'
df_share_avg['Indicator'] = 'Share of Women in Top Percentiles'
df_ratio_female_male_avg.rename(columns={'Ratio of female to male labor force participation rate (%) (modeled ILO estimate)': 'Value'}, inplace=True)
df_gender_avg.rename(columns={'Gender wage gap (%)': 'Value'}, inplace=True)
df_mortality_avg.rename(columns={'Maternal Mortality Ratio (Gapminder (2010) and World Bank (2015))': 'Value'}, inplace=True)
df_share_avg.rename(columns={'Share of women in top 0.1%': 'Value'}, inplace=True)
combined_df = pd.concat([df_ratio_female_male_avg, df_gender_avg, df_mortality_avg, df_share_avg])
thisdict = {
0: 'Ratio of Female to Male Labor Force Participation Rate',
1: 'Gender Wage Gap',
2: 'Maternal Mortality Ratio',
3: 'Share of Women in Top Percentiles'
}
app = Dash(__name__)
from dash import html
from dash.dependencies import Input, Output
from plotly.subplots import make_subplots
app.layout = html.Div([
html.H4('Waterfall Chart for Gender-Related Indicators'),
dcc.Dropdown(
id="indicator-selector",
options=[{'label': indicator, 'value': indicator} for indicator in combined_df['Indicator'].unique()],
value=combined_df['Indicator'].unique()[0],
clearable=False,
),
dcc.Graph(id="waterfall-subplots"),
])
continent_colors = {
'Africa': 'rgba(255, 0, 0, 0.7)',
'Asia': 'rgba(0, 255, 0, 0.7)',
'Europe': 'rgba(0, 0, 255, 0.7)',
'North America': 'rgba(255, 255, 0, 0.7)',
'Oceania': 'rgba(255, 0, 255, 0.7)',
'South America': 'rgba(0, 255, 255, 0.7)'
}
@app.callback(
Output("waterfall-subplots", "figure"),
[Input("indicator-selector", "value")])
def update_waterfall_subplots(selected_indicator):
num_continents = len(combined_df['Continent'].unique())
fig = make_subplots(rows=(num_continents + 1) // 2, cols=2)
for i, continent in enumerate(combined_df['Continent'].unique(), 1):
df_filtered = combined_df[(combined_df['Indicator'] == selected_indicator) & (combined_df['Continent'] == continent)]
df_filtered = df_filtered.sort_values('Year')
df_filtered['Change'] = df_filtered['Value'].diff().fillna(0)
trace = go.Waterfall(
name=continent,
orientation="v",
measure=["relative"] * len(df_filtered),
x=df_filtered['Year'].astype(str),
textposition="outside",
y=df_filtered['Change'],
connector={"line": {"color": "rgb(63, 63, 63)"}},
increasing_marker_color=continent_colors[continent],
decreasing_marker_color=continent_colors[continent],
)
row = (i - 1) // 2 + 1
col = (i - 1) % 2 + 1
fig.add_trace(trace, row=row, col=col)
fig.update_layout(
title=f"Waterfall Chart of {selected_indicator} in Each Continent",
showlegend=True
)
return fig
app.run_server(debug=True, port=8083, mode='inline')
import plotly.express as px
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
df_ratio_female_male_avg['Indicator'] = 'Ratio of Female to Male Labor Force Participation Rate'
df_gender_avg['Indicator'] = 'Gender Wage Gap'
combined_df = pd.concat([df_ratio_female_male_avg, df_gender_avg])
fig = make_subplots(rows=1, cols=2, subplot_titles=['Participação da mulher no trabalho', 'Disparidade salarial'])
for i, df in enumerate([df_ratio_female_male_avg, df_gender_avg], 1):
heatmap_data = df.pivot(columns='Year', index='Continent', values='Value')
trace = go.Heatmap(
z=heatmap_data.values,
x=heatmap_data.columns,
y=heatmap_data.index,
colorscale='Viridis',
colorbar=dict(title=df['Indicator'].iloc[0]),
)
fig.add_trace(trace, row=1, col=i)
fig.update_layout(height=900, width=1500, title_text='Comparar Heatmaps da Partificação da mulher no trabalho e as disparidades salariais', showlegend=False)
fig.show()
import plotly.graph_objects as go
from plotly.subplots import make_subplots
import pandas as pd
def prepare_data(df, year_col, value_cols, entity_col):
df_filtered = df[(df[year_col] >= 1990) & (df[year_col] <= 2015)]
df_avg = df_filtered.groupby(entity_col).mean().reset_index()
result = pd.DataFrame()
for value_col in value_cols:
top_5 = df_avg.nlargest(5, value_col)
bottom_5 = df_avg.nsmallest(5, value_col)
top_5['Group'] = 'Top 5 - ' + value_col
bottom_5['Group'] = 'Bottom 5 - ' + value_col
combined = pd.concat([top_5, bottom_5])
combined['Category'] = value_col
result = pd.concat([result, combined])
return result
colunas_share = ['Share of women in top 0.1%', 'Share of women in top 0.25%', 'Share of women in top 0.5%', 'Share of women in top 1%', 'Share of women in top 10%', 'Share of women in top 5%']
df_ratio_combined = prepare_data(df_ratio, 'Year', ['Female to male ratio of time devoted to unpaid care work (OECD (2014))'], 'Entity')
df_share_combined = prepare_data(df_share, 'Year', colunas_share, 'Entity')
df_ratio_fm_combined = prepare_data(df_ratio_female_male, 'Year', ['Ratio of female to male labor force participation rate (%) (modeled ILO estimate)'], 'Entity')
df_mortality_combined = prepare_data(df_mortality, 'Year', ['Maternal Mortality Ratio (Gapminder (2010) and World Bank (2015))'], 'Entity')
df_gender_combined = prepare_data(df_gender, 'Year', ['Gender wage gap (%)'], 'Entity')
fig = make_subplots(rows=3, cols=2, subplot_titles=('Ratio', 'Share', 'Ratio Female to Male Labor Force', 'Maternal Mortality', 'Gender Wage Gap'))
fig.add_trace(go.Bar(x=df_ratio_combined['Entity'], y=df_ratio_combined['Female to male ratio of time devoted to unpaid care work (OECD (2014))'], name='Ratio'), row=1, col=1)
for coluna in colunas_share:
df_filtered = df_share_combined[df_share_combined['Category'] == coluna]
fig.add_trace(go.Bar(x=df_filtered['Entity'], y=df_filtered[coluna], name=coluna), row=1, col=2)
fig.add_trace(go.Bar(x=df_ratio_fm_combined['Entity'], y=df_ratio_fm_combined['Ratio of female to male labor force participation rate (%) (modeled ILO estimate)'], name='Ratio FM'), row=2, col=1)
fig.add_trace(go.Bar(x=df_mortality_combined['Entity'], y=df_mortality_combined['Maternal Mortality Ratio (Gapminder (2010) and World Bank (2015))'], name='Maternal Mortality'), row=2, col=2)
fig.add_trace(go.Bar(x=df_gender_combined['Entity'], y=df_gender_combined['Gender wage gap (%)'], name='Gender Wage Gap'), row=3, col=1)
fig.update_layout(barmode='stack', height=1200, width=1200, title_text="Comparação dos Top 5 e Bottom 5 Países em Vários Indicadores (1990-2015)")
fig.show()
# visualização 5 - Radial Bar chart por DECADAS
# https://datavizproject.com/data-type/circular-bar-chart/
from dash import Dash, dcc, html, Input, Output
import pandas as pd
import plotly.graph_objects as go
from plotly.subplots import make_subplots
df_ratio_avg['Indicator'] = 'Female to male ratio of time devoted to unpaid care work'
df_share_avg['Indicator'] = 'Share of Women in Top Percentiles'
df_ratio_female_male_avg['Indicator'] = 'Ratio of Female to Male Labor Force Participation Rate'
df_mortality_avg['Indicator'] = 'Maternal Mortality Ratio'
df_gender_avg['Indicator'] = 'Gender Wage Gap'
df_ratio_female_male_avg.rename(columns={'Ratio of female to male labor force participation rate (%) (modeled ILO estimate)': 'Value'}, inplace=True)
df_share_avg.rename(columns={'Share of women in top 0.1%': 'Value'}, inplace=True)
df_ratio_female_male_avg.rename(columns={'Current Column Name': 'New Column Name'}, inplace=True)
df_mortality_avg.rename(columns={'Maternal Mortality Ratio (Gapminder (2010) and World Bank (2015))': 'Value'}, inplace=True)
df_gender_avg.rename(columns={'Gender wage gap (%)': 'Value'}, inplace=True)
combined_df['Decade'] = (combined_df['Year'] // 10 * 10).astype(str) + '-' + ((combined_df['Year'] // 10 * 10) + 9).astype(str)
app = Dash(__name__)
app.layout = html.Div([
html.H4('Radial Bar Chart for Gender-Related Indicator'),
dcc.Dropdown(
id="indicator-selector",
options=[{'label': indicator, 'value': indicator} for indicator in combined_df['Indicator'].unique()],
value=combined_df['Indicator'].unique()[0],
clearable=False,
),
dcc.Graph(id="radial-bar-chart"),
])
@app.callback(
Output("radial-bar-chart", "figure"),
[Input("indicator-selector", "value")])
def update_radial_chart(selected_indicator):
fig = make_subplots(rows=1, cols=3, subplot_titles=['1990-1999', '2000-2009', '2010-2015'], specs=[[{'type': 'polar'}, {'type': 'polar'}, {'type': 'polar'}]])
for i, decade in enumerate([1990, 2000, 2010]):
df_filtered = combined_df[(combined_df['Indicator'] == selected_indicator) & (combined_df['Decade'] == f"{decade}-{decade+9}")]
trace = go.Barpolar(
r=df_filtered['Value'],
theta=df_filtered['Continent'],
marker_color=df_filtered['Value'],
marker_line_color="black",
marker_line_width=2,
opacity=0.7,
name=f"{decade}-{decade+5}"
)
fig.add_trace(trace, row=1, col=i+1)
fig.update_layout(
polar=dict(
radialaxis=dict(
visible=True,
range=[0, combined_df['Value'].max()]
)
),
showlegend=True,
title_text=f"Radial Bar Chart of {selected_indicator} by Decade"
)
return fig
if __name__ == '__main__':
app.run_server(debug=True, port=8423)